from interface.member import MemberInterface
from utils.request_method import SendMethod


class OrderInterface:


    def __init__(self, headers):
        self.url = 'http://47.108.206.100:8085'
        self.headers = headers

    #确认订单
    def comfirm_order(self, body):
        method = 'post'
        url = self.url + '/order/generateConfirmOrder'
        playload = [body]
        return SendMethod.send_method(method, url, json=playload, headers=self.headers)

    #生成订单
    def generate_order(self, card_id):
        method = 'post'
        url = self.url + '/order/generateOrder'
        params = {
            "cartIds": [
                card_id
            ],
            "memberReceiveAddressId": 3061,
            "payType":1
        }
        return SendMethod.send_method(method=method, url=url, json=params, headers=self.headers)

    #支付
    def success_pay(self,orderId):
        method='post'
        url=self.url+'/order/paySuccess'
        body={
            'orderId': orderId,
            'payType': 1
        }
        return SendMethod.send_method(method,url,data=body,headers=self.headers)



if __name__ == '__main__':
    body = {
        "username": "海绵宝宝",
        "password": '123456'
    }
    headers = MemberInterface().get_token_head(body)
    oi=OrderInterface(headers)
    print(oi.comfirm_order(4146))#确定订单
    print(oi.generate_order(4199))
    orderId={
        'orderId': 5264,
        'payType': 0
    }
    print(oi.success_pay(orderId))



